<%-- Page display list of trainees. --%>

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.kha.Trainee"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ page errorPage="WEB-INF/errorpage.jsp"%>

<%
	// Get trainee bean from session, if not existed or not valid, redirect to homepage.
	Trainee trainee = (Trainee) session.getAttribute("trainee");

	if (trainee == null || trainee.isValid() != true) {
		response.sendRedirect("index.jsp");
	}
%>

<!DOCTYPE html>
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Trainee Listn</title>
<link rel="stylesheet" type="text/css" href="vendor/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="vendor/css/docs.css">
<link rel="stylesheet" type="text/css" href="vendor/css/docs_list.css">
<script src="vendor/js/bootstrap.min.js"></script>

</head>

<body>

	<div class="navbar navbar">
		<div class="navbar-inner">

			<div class="container">
				<a class="brand" href="#">Trainee Registration</a>
			</div>

		</div>
	</div>

	<div class="container-fluid">

		<div class="row-fluid">

			<div class="bs-docs-example span3" style="height: 300px;">
				<!-- Display inputted information. -->
				<label for="account">Account</label> <em id="account"><%=trainee.getAccount()%></em>

				<label for="firstname">Firstname</label> <em id="firstname"><%=trainee.getFirstname()%></em>

				<label for="lastname">Lastname</label> <em id="lastname"><%=trainee.getLastname()%></em>

				<label for="email">Email</label> <em id="email"><%=trainee.getEmail()%></em>
				<hr />
				<div class="container-fluid">
					<div class="row-fluid">

						<form action="TraineeServlet" class="span6" method="post">
							<input type="hidden" name="hidden" value="update" />
							<button type="submit" class="btn">Update</button>
						</form>

						<form action="TraineeServlet" class="span6" method="post">
							<input type="hidden" name="hidden" value="save" />
							<button type="submit" class="btn btn-success">Save</button>
						</form>
					</div>

				</div>

				<%
					// Get message.
					Object obj = request.getAttribute("message");

					if (obj != null) {
						// Display message.
						%>
							<jsp:include page="/WEB-INF/view/info.jsp">
								<jsp:param value="<%=obj.toString()%>" name="msg" />
							</jsp:include>
						<%
					}
				%>

			</div>

			<div class="bs-docs-example2 span8"
				style="overflow-y: scroll; overflow-x: hidden; height: 480px;">

				<table class="table table-bordered">
					<thead>
						<tr>
							<th>Account</th>
							<th>Firstname</th>
							<th>Lastname</th>
							<th>Email</th>
						</tr>
					</thead>
					<tbody>

						<%
							// Get list of trainees.
							// Pull out ArrayList<Trainee> from session.
							ArrayList<Trainee> result = (ArrayList<Trainee>) request
									.getAttribute("result"); // Don't how to fix the warning :((

							if (result != null) {

								int size = result.size();

								// Show each item from list.
								for (int i = 0; i < size; i++) {

									String account = result.get(i).getAccount();
									String firstname = result.get(i).getFirstname();
									String lastname = result.get(i).getLastname();
									String email = result.get(i).getEmail();

									out.print("<tr>");
									out.print("<td>" + account + "</td>");
									out.print("<td>" + firstname + "</td>");
									out.print("<td>" + lastname + "</td>");
									out.print("<td>" + email + "</td>");
									out.print("<tr>");

								}

							}
						%>

					</tbody>
				</table>
			</div>
		</div>

	</div>
</body>
</html>